package com.sumapay.fsb.gensrc.mapper;

import com.sumapay.fsb.gensrc.entity.FsbBankCard;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author suma
 * @since 2021-03-16
 */
public interface FsbBankCardMapper extends BaseMapper<FsbBankCard> {
    @Select("SELECT t.CARD_TYPE,i.BANK_NAME FROM (SELECT t.*, CASE WHEN length(t.bank_identity) = temp.max_len THEN 1 ELSE 0 END length_flag FROM " +
            "fsb_bank_card_bin_list t,(SELECT ifnull (min(t.bank_identity),'不匹配') min_bank_id,max(t.len) max_len FROM(SELECT bank_identity," +
            "length(t.bank_identity) len FROM fsb_bank_card_bin_list t WHERE substr(#{bankId,jdbcType=VARCHAR},1,length(t.bank_identity)) = " +
            "t.bank_identity) t) temp WHERE t.bank_identity LIKE CONCAT(temp.min_bank_id, '%')ORDER BY length_flag DESC) t ,fsb_bank_info i " +
            "WHERE t.BANK_CODE=i.BANK_CODE")
    Map<String,String> getCardBin(@Param("bankId") String bankId);
}
